//---------------------------给弹出层写一下“ 按到非 弹出层区域就消失 ”--------------------
	document.addEventListener('click',function(e){
            var parent=$(e.target).parents('.popUp,.bs');
            if(parent.length===0){
                //操作此区域
                $("#popUp").attr({"class":"popUp"});
            }else{
                //console.log('按钮与弹层区');
            }
        });
//-------------------------------------将Ajax抽象方法--------------------------------------
	function  myAjax(urls){
		$.ajax({
			type:"get",
			url:"http://192.168.60.164:8080/"+ urls +"",
			async:true,
			dataType:"json",
			success:function(info){
				var obj = info.data;
				var str = "";
				for(var i=0; i<obj.length; i++)
				{
					str+=
						'<tr>'+
							'<td><input name="status" type="radio" data-id="'+obj[i].equipmentNo+'" /></td>'+
					  		'<td>'+obj[i].equipmentName+'</td>'+
					  		'<td>'+obj[i].useStatus+'</td>'+
					  		'<td>'+obj[i].userName+'</td>'+
					  		'<td>'+obj[i].place+'</td>'+
					  		'<td>'+obj[i].price+'</td>'+
				  		'</tr>';				  	
				}			
				$("#tbody1").html(str);
			}
		});
	}
//---------------------------显示所有设备的简略字段信息  ，发送Ajax请求。-------------------
	var urls = "/test/list/basic/get_equipments";
	myAjax(urls);
	$(".navInfo .navFour").eq(0).click(function(){
		$("#lifeCycle").css({"display":"inline-block"});
		$("#transer").css({"display":"inline-block"});
		$("#change").css({"display":"none"});
		var urls = "/test/list/basic/get_equipments";	
		myAjax(urls);
	});
	//-----点击使用过的设备
	$(".navInfo .navFour").eq(1).click(function(){
		$("#lifeCycle").css({"display":"inline-block"});
		$("#transer").css({"display":"inline-block"});
		$("#change").css({"display":"none"});
		var urls = "/test/list/basic/get_equipments";
		myAjax(urls);
	});
	/*
	//-----点击未审核通关过的设备信息
	$(".navInfo .navFour").eq(2).click(function(){
		//var urls = "/test/list/basic/get_equipments";
		//myAjax(urls);
		$("#lifeCycle").css({"display":"none"});
		$("#transer").css({"display":"none"});
		$("#change").css({"display":"inline-block"});
	});
	*/
	
//---------------------------如果我点击“详细按钮”，通过id显示内容------------------------	
	$("#detailedInfo").click(function(){
		var ids = undefined;
		var a = $(" #formCheck input[type='radio'] ");
		for(let i=0; i<a.length; i++)
		{
			if($(a[i]).attr('checked')){
				ids = $(a[i]).attr("data-id");			
			}
		}
		//为了避免 id为空，进行终止
		if(ids == undefined){
			layer.alert('亲，勾选单选按钮哦', {
			    skin: 'layui-layer-lan'
			    ,closeBtn: 0
			    ,anim: 4 //动画类型
			 });
			return;
		}
		//（1）后端给过来的是“对象”		
		$.ajax({
			url: "http://192.168.60.164:8080/test/detail/get_equipment/"+ids+"",
			type:"GET",
			async: true,
			dataType:"json",
			success: function(info){
			
				var obj1 = info.data;				
				var str1 = "";
				str1+=
					'<tr>'+
						'<td>设备编号</td>'+
				  		'<td>设备名称</td>'+
				  		'<td>当前使用状态</td>'+
				  		'<td>当前使用人</td>'+
				  		'<td>存放地点</td>'+
				  		'<td>细类别</td>'+
			  		'</tr>'+
					'<tr>'+
						'<td>'+info.equipmentNo+'</td>'+
				  		'<td>'+info.equipmentName+'</td>'+
				  		'<td>'+info.useStatus+'</td>'+
				  		'<td>'+info.userName+'</td>'+
				  		'<td>'+info.place+'</td>'+
				  		'<td>'+info.equipmentCategory+'</td>'+
			  		'</tr>';
			  	var str2 ="";
			  		str2+=
					'<tr>'+
						
				  		'<td>单价</td>'+
				  		'<td>型号</td>'+
				  		'<td>折旧状态</td>'+
				  		'<td>折旧年限</td>'+
				  		'<td>出货票号码</td>'+
			  		'</tr>'+
					'<tr>'+
				  		'<td>'+info.price+'</td>'+
				  		'<td>'+info.type+'</td>'+
				  		'<td>'+info.depreciationStatus+'</td>'+
				  		'<td>'+info.depreciationPeriod+'</td>'+
				  		'<td>'+info.shippingNo+'</td>'+
			  		'</tr>';
			  	var str3 = "";
			  		str3+=
					'<tr>'+
						'<td>供货单位</td>'+
				  		'<td>进货日期</td>'+
				  		'<td>用途</td>'+
				  		'<td>出产厂家</td>'+
				  		'<td>制造号</td>'+
				  		'<td>利用率</td>'+
			  		'</tr>'+
					'<tr>'+
						'<td>'+info.deliveryUnit+'</td>'+
				  		'<td>'+info.purchaseDate+'</td>'+
				  		'<td>'+info.application+'</td>'+
				  		'<td>'+info.manufacturer+'</td>'+
				  		'<td>'+info.manufacturerNo+'</td>'+
				  		'<td>'+info.shippingNo+'</td>'+
			  		'</tr>';
			  	 $("#popUp table").eq(0).html(str1);
			  	 $("#popUp table").eq(1).html(str2);
			  	 $("#popUp table").eq(2).html(str3);
			  	 //让内容以弹出层的方式显示出来。
			  	 $("#popUp").attr({"class":"popUpClick"});
			  	
			},
			error:function(){
				console.log('获取设备详细信息失败！！！');
			}
		});	
	});
	
	
//-------------------------生命周期  = 关于这个设备的关键字段（上面一行简略字段） + 使用表信息（使用记录）-----------------
	$("#lifeCycle").click(function(){
		var ids = undefined;
		var a = $("#formCheck input[type='radio']");
		for(let i=0; i<a.length; i++)
		{
			if($(a[i]).attr('checked')){
				ids = $(a[i]).attr("data-id");			
			}
		}
		if(ids == undefined){
			layer.alert('亲，勾选单选按钮哦', {
			    skin: 'layui-layer-lan'
			    ,closeBtn: 0
			    ,anim: 4 //动画类型
			 });
			return;
		}
		 
		//---关键字段信息
		$.ajax({
			type:'get',
			url:"http://192.168.60.164:8080/test/basic/get_equipment/"+ids+"",
			dataType:'json',
			success:function(info){
				var info = info.data
				var str1 = "";
				str1+=
					'<tr>'+
						'<td></td>'+
				  		'<td>'+info.equipmentName+'</td>'+
				  		'<td>'+info.useStatus+'</td>'+
				  		'<td>'+info.userName+'</td>'+
				  		'<td>'+info.place+'</td>'+
				  		'<td>'+info.price+'</td>'+
				  	'</tr>';
				 $("#tbody1").html(str1);
			},
			error:function(){
				console.log('ajax请求失败');
			}
		});
		
		
		//------------使用信息-------------
		$.ajax({
			type:'get',
			url:"http://192.168.60.164:8080/test/basic/get_record/"+ids+"",
			dataType:'json',
			success:function(info){
				var str2 = "";
				for(let i=0; i<info.length; i++)
				{
					str2+=					
						'<tr>'+
							'<td></td>'+
					  		'<td>'+info[i].userNo+'</td>'+
					  		'<td>'+info[i].userName+'</td>'+
					  		'<td>'+info[i].beginDate+'</td>'+
					  		'<td>'+info[i].endDate+'</td>'+
					  		'<td>'+info[i].auditor+'</td>'+
				  		'</tr>'
				}
				var t1 =
						'<p>'+
						'<p>'+
							'<tr style="margin-top: 30px;">'+
									'<td><h4>该设备使用记录</h4></td>'+
									'<td>设备编号</td>'+
							  		'<td>使用人</td>'+
							  		'<td>开始时间</td>'+
							  		'<td>结束时间</td>'+
							  		'<td>审核人</td>'+
						  	'</tr>'+
						  	str2+
						'</p>'+
						'</p>';
				document.getElementById("tbody1").innerHTML+=t1;
			},
			error:function(){
				console.log('ajax请求失败');
			}
		});
	});	